package Observer;

import java.util.ArrayList;
import java.util.List;

// 具体被观察者 - 环境传感器网络
public class EnvironmentSensorNetwork implements EnvironmentSubject {
    private List<EnvironmentObserver> observers = new ArrayList<>();
    private EnvironmentData currentData;

    @Override
    public void registerObserver(EnvironmentObserver observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(EnvironmentObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(EnvironmentData data) {
        for (EnvironmentObserver observer : observers) {
            observer.update(data);
        }
    }

    public void setEnvironmentData(EnvironmentData newData) {
        this.currentData = newData;
        notifyObservers(newData);
    }

    // 添加获取当前环境数据的方法
    public EnvironmentData getCurrentData() {
        return currentData;
    }
}